<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:cc="http://java.sun.com/jsf/composite">

    <!-- INTERFACE -->
    <cc:interface>:
        <cc:attribute name="formName" required="true"/>
        <cc:attribute name="usernamePrompt" default="Username: "/>
        <cc:attribute name="passwordPrompt" default="Password: "/>

        <cc:attribute name="loginButtonText" default="Log In"/>
        <cc:attribute name="loginManagerBean"/>
        <cc:editableValueHolder name="usernameVal" targets="form:name"/>
        <cc:editableValueHolder name="passwordVal" targets="form:password"/>
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <p:panel>
            <h:form id="loginForm">
                <h2><h:outputLabel value="#{cc.attrs.formName}"/></h2>
                <p:messages id="msgs" showDetail="false"/>
                <h:panelGrid columns="3" summary="">
                    <h:outputLabel for="username" value="#{cc.attrs.usernamePrompt}"/>
                    <p:inputText required="true" requiredMessage="Field is required." id="username" value="#{cc.attrs.loginManagerBean.username}"/>
                    <p:message for="username"/>

                    <h:outputLabel for="password" value="#{cc.attrs.passwordPrompt}"/>
                    <h:inputSecret required="true" requiredMessage="Field is required." id="password" value="#{cc.attrs.loginManagerBean.password}"/>
                    <p:message for="password"/>
                </h:panelGrid>
                <h:panelGroup rendered="#{loginManagerBean.renderedCaptcha}">
                    <h:graphicImage id="capimg" value="#{facesContext.externalContext.requestContextPath}/../Captcha.jpg"/>
                    <p:inputText id="inputtedCaptcha" value="#{loginManagerBean.inputtedCaptcha}" required="true" requiredMessage="Please input captcha."/>
                    <p:message for="inputtedCaptcha"/>
                </h:panelGroup>
                <p>
                    <p:commandButton id="loginButton" value="#{cc.attrs.loginButtonText}" ajax="false" action="#{loginManagerBean.login}" />
                </p>
            </h:form>
            <h:form>
                <p:commandLink value="Forgot your password?" action="#{loginManagerBean.redirectToPasswordReminder}"/>
            </h:form>
        </p:panel>
    </cc:implementation>
</html>